#ifndef _STRAWGUI_COMPONENT_RECT_INSTANCE_H_
#define _STRAWGUI_COMPONENT_RECT_INSTANCE_H_

#ifdef _EDITOR
#include "sRTTIObject.h"
#endif
#include "sGUIObject.h"
#include "sMath.h"
#include "sDrawStack.h"
#include "sComponentInstance.h"
#include "sControllerEvents.h"

namespace sgui
{
namespace res
{
	class sComponentRect;
};
namespace inst
{

class sComponentRectInstance: public obs::sObserver
{
protected:
	math::sRectsf					m_rect;
	const res::sComponentRect&		m_component;
	sComponentInstance&		        m_instance;
	math::sPointf					m_offset;
    s32                             m_id;
private:
	void updateOffset();

	friend sComponentInstance;
public:
	const res::sComponentRect& getComponent() const { return m_component; }
	template <class TO> const TO& get() const { return (const TO&)(m_component); }
	sComponentInstance& getInstance() { return m_instance; }
	const sComponentInstance& getInstance() const { return m_instance; }

    const s32 getID() const { return m_id; }
    void setID(s32 id) { m_id = id; }

	math::sRectsf& getRect();
	const math::sRectsf& getRect() const;
	const math::sPointf& getOffset() const;
	bool OnEvent(const obs::sEvent& event);
    
    virtual void OnHoverGet();
    virtual void OnHoverRelease();
    virtual bool OnPress(const obs::sMousePressEvent& event);

	const EControlState& getState() const;

	virtual void draw(engine::sDrawStack& drawStack) const = 0;
	virtual void update();

	sComponentRectInstance(const res::sComponentRect& componentRect, sComponentInstance& instance, s32 id);
    virtual ~sComponentRectInstance();
};

};
};

#endif